package com.altekis.kanbankaze.client;

import com.altekis.kanbankaze.shared.KanbanProperties;
import com.altekis.kanbankaze.shared.UserStory;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.HasText;

/**
 * User story on board presenter
 */
public class UserStoryCardPresenter {
	interface Display {
		HasText getTitleField();
		HasText getNameField();
		HasText getDescriptionField();
		HasClickHandlers getEditButton();
		HasClickHandlers getFlipButton();
		HasClickHandlers getFlipButton2();
		void setPixelPosition(int x, int y);
		void expandCollapse();
		void flip();
	}

	protected Display display;
	protected UserStory userStory;
	protected TaskServiceAsync taskService;
	
	UserStoryCardPresenter(TaskServiceAsync taskService) {
		this.taskService = taskService;
	}

	void bindDisplay(final Display display) {
		this.display = display;

		display.getEditButton().addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				doEdit();
			}
		});
		
		display.getFlipButton().addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				display.flip();
			}
		});
		
		display.getFlipButton2().addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				display.flip();
			}
		});
	}

	void show(UserStory userStoryToShow, KanbanProperties kanbanProperties) {
		userStory = userStoryToShow;
		display.getTitleField().setText("H" + userStory.getId());
		display.getNameField().setText(userStory.getName());
		display.getDescriptionField().setText(userStory.getDescription());
	}

	void refresh() {
		display.getNameField().setText(userStory.getName());
		display.getDescriptionField().setText(userStory.getDescription());
	}

	public void doEdit() {
		this.display.expandCollapse();
	}
}
